package com.yimixian.app.receiver;

import com.yimixian.app.SystemFramework;
import com.yimixian.app.common.Constants;

import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.v4.content.LocalBroadcastManager;

/**
 * Created by songzhiyang on 2015/8/31.
 */
public class ButtonClickTransHelper {

  public void registGetTypeGiftBroadCastReceiver(BroadcastReceiver receiver) {
    IntentFilter filter = new IntentFilter();
    filter.addAction(Constants.TYPE_GIFT_FLAG_BROADCAST);
    LocalBroadcastManager.getInstance(SystemFramework
        .getInstance().getGlobalContext()).registerReceiver(receiver, filter);
  }

  public void registGetTypeGiftBroadCastReceiver(BroadcastReceiver receiver,IntentFilter filter) {
    LocalBroadcastManager.getInstance(SystemFramework
        .getInstance().getGlobalContext()).registerReceiver(receiver, filter);
  }

  public void unRegistGetTypeGiftBroadCastReceiver(BroadcastReceiver receiver) {
    LocalBroadcastManager.getInstance(SystemFramework
        .getInstance().getGlobalContext()).unregisterReceiver(receiver);
  }

  public void sendButtonClickBroadCast(String action,int goodId) {
    Intent intent = new Intent(action);
    intent.putExtra(Constants.GOOD_ID,goodId);
    LocalBroadcastManager.getInstance(SystemFramework.getInstance().getGlobalContext()).sendBroadcast(intent);
  }

  public void sendButtonClickBroadCast(String action,int goodId,float price) {
    Intent intent = new Intent(action);
    intent.putExtra(Constants.GOOD_ID,goodId);
    intent.putExtra(Constants.ITEM_GIGTTYPE_MIN_PRICE,price);
    LocalBroadcastManager.getInstance(SystemFramework.getInstance().getGlobalContext()).sendBroadcast(intent);
  }

  public void sendNormalBroadCast(String action) {
    Intent intent = new Intent(action);
    LocalBroadcastManager.getInstance(SystemFramework.getInstance().getGlobalContext()).sendBroadcast(intent);
  }
  public void registNormalBroadCastReceiver(BroadcastReceiver receiver,IntentFilter filter) {
    LocalBroadcastManager.getInstance(SystemFramework
        .getInstance().getGlobalContext()).registerReceiver(receiver, filter);
  }
  public void unRegistNormalBroadCastReceiver(BroadcastReceiver receiver) {
    LocalBroadcastManager.getInstance(SystemFramework
        .getInstance().getGlobalContext()).unregisterReceiver(receiver);
  }
}
